﻿using CheckIn.AdminServer.UserInfoDBModels;
using DawnAdminServer.Attributes;
using System.ComponentModel.DataAnnotations.Schema;

namespace CheckIn.AdminServer.Controllers.PlanSrc
{
    using CheckIn.AdminServer.PlanDBModels;
    using CheckIn.AdminServer.UserInfoDBModels;
    using DawnAdminServer.Attributes;
    using DawnAdminServer.Controllers;
    using DawnAdminServer.Dtos;
    using Microsoft.AspNetCore.Mvc;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Way.EntityDB;

    [MatchPath("plan/CheckInHistoryView")]
    public class PlanCheckInHistoryController : EfReadonlyControllerBase<PlanDBContext, CheckInHistory, CheckInHistorySearchModel>
    {
        protected override string OrderExpression => "Likes desc,id desc";

        public override async Task<PageData<object>> List([FromBody] CheckInHistorySearchModel model)
        {
            var ret = await base.List(model);

            foreach( DataItem item in ret.Datas)
            {
                item.ChangedProperties.Clear();
            }
            return ret;
        }

    }


    public class CheckInHistorySearchModel : SearchRequestModel
    {
        public Int64? UserId { get; set; }
        [EndDatePlus(1)]
        public DateTime[] Date { get; set; }
    }
}

namespace CheckIn.AdminServer.PlanDBModels
{
    public partial class CheckInHistory
    {
        [NotMapped]
        [AssociatedQuery(
       PropertyName = nameof(CheckInHistory.UserId),
       DbContextName = nameof(UserInfoDBContext),
       TableName = nameof(UserInfo),
       IdName = "id",
       CaptionName = nameof(UserInfo.Name))]
        public string UserName { get; set; }

        [NotMapped]
        [AssociatedQuery(
      PropertyName = nameof(CheckInHistory.ItemId),
      DbContextName = nameof(PlanDBContext),
      TableName = nameof(CheckInItem),
      IdName = "id",
      CaptionName = nameof(CheckInItem.Title))]
        public string ItemName { get; set; }
    }
}